//缓存的Key
export const Keys = {

};

/* 设置区别不同登录用户 */
export function setKeys(name, imUserName) {
	if (name && (typeof name == 'string') && Keys.hasOwnProperty(name)) {
		Keys[name] = Keys[name] + '_' + imUserName;
	}
}

//App缓存数据
class Cache {

    setItem(key, value) {
        try {
            window.setStorageSync(key, value);
            if(key == Keys.accessToken){
                uni.setStorageSync(Keys.tokenExpTime, new Date().getTime());
            }
        } catch (e) {
            console.log(e);
        }
    }

    getItem(key) {
        return uni.getStorageSync(key)
    }

    removeItem(key) {
        return uni.removeStorageSync(key)
    }

    /**
     * 登录后的会员信息
     * @return {如果返回null，则需要重新登录}
     */
    user(){
       const user = uni.getStorageSync(Keys.user);
       if(user === '' || user === null){
           return null;
       }
       return user;
    }
	/**
	 * 清除缓存信息
	 */
	cleanAll(){
		uni.removeStorageSync(Keys.user);
		uni.removeStorageSync(Keys.accessToken);
		uni.removeStorageSync(Keys.gestureCode);
		uni.removeStorageSync(Keys.currentFileArr);
	}
};


export default new Cache();
